﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;


var builder = WebApplication.CreateBuilder(args);
// 添加JSON配置文件
builder.Configuration.AddJsonFile(@"F:\song\SeerAGV\Config\appsettings.json");

// 绑定配置节到AgvOptions类
builder.Services.Configure<AgvOptions>(builder.Configuration.GetSection("Agv"));

// build an app
var app = builder.Build();

// 使用依赖注入获取AgvOptions实例

var options = app.Services.GetService<IOptions<AgvOptions>>()!.Value;


Console.WriteLine(options.Infos);
Console.WriteLine(options.Infos==null);


foreach(var info in options.Infos!){
    Console.WriteLine(info.Name);
    Console.WriteLine(info.Ip);
    Console.WriteLine(info.Ports);
    Console.WriteLine(info.Ports == null);
    break;
    // foreach(var port in info.Ports!){
    //     Console.WriteLine(port);
    // }

}



